package com.basic.bio.chat.groupchatdemo;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Description:服务器端
 * @Author:Zc9741
 * @QQ:516906531
 */
public class Server {

    public static ArrayList<Socket> sockets = new ArrayList<>();

    public static void main(String[] args) throws IOException {
        //创建ServerSocket对象
        ServerSocket serverSocket=new ServerSocket(4567);

        //等待链接
        while(true) {
            try {
                Socket socket = serverSocket.accept();
                sockets.add(socket);
                System.out.println("连接成功");
                //创建一个线程用于发送数据
                ServerSendRunnable serverSendRunnable = new ServerSendRunnable(socket);
                new Thread(serverSendRunnable).start();

                //创建一个线程用于接受数据
                ServerReceiveRunnable serverReceiveRunnable = new ServerReceiveRunnable(socket);
                new Thread(serverReceiveRunnable).start();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

